﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;
using System.Drawing.Design;
using System.IO;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace DamageCalculator.Classes
{
    [DefaultPropertyAttribute("GameName"), XmlRoot("GameSettings")]
    public class GameSettings
    {
        [Serializable]
        public enum TimeStampFormat
        {
            None,
            EpochDays,
            EpochHours,
            EpochMinutes,
            EpochSeconds,
            EpochMS,
            EpochTicks,
            DateTimeString,
        }

        [XmlAttribute("GameName")]
        private String mGameName;

        [XmlAttribute("LogFilePath")]
        private String mLogFilePath;

        [XmlAttribute("EntrySeperator")]
        private String mEntrySeperator;

        [XmlAttribute("TimeStampFormat")]
        private TimeStampFormat mTimeStampFormat;

        [XmlAttribute("DateTimeStringFormat")]
        private String mDateTimeStringFormat;

        [XmlAttribute("EpochTime")]
        private DateTime mEpochTime;

        [XmlAttribute("UseFullTimes")]
        private bool mUseFullTimes;

        [XmlAttribute("LogClears")]
        private bool mLogClearsOnClose;

        [XmlAttribute("AutoRead")]
        private bool mAutoRead;

        [XmlArray("LogEntryFormats"), XmlArrayItem("LogEntryFormat")]
        List<ParsableLogEntry> Entries;

        [XmlAttribute("PlayerName")]
        String mPlayerName;

        public GameSettings()
        {
            this.Entries = new List<ParsableLogEntry>();
        }

        public GameSettings(String pGameName, String pLogFilePath, String pEntrySeperator, TimeStampFormat pTSFormat, String pDateTimeStringFormat, DateTime pEpochTime, bool pUseFullTimes, bool pLogClearsOnClose, bool pAutoread)
            :this()
        {
            this.mGameName = pGameName;
            this.mLogFilePath = pLogFilePath;
            this.mEntrySeperator = pEntrySeperator;
            this.mTimeStampFormat = pTSFormat;
            this.mDateTimeStringFormat = pDateTimeStringFormat;
            this.mEpochTime = pEpochTime;
            this.mUseFullTimes = pUseFullTimes;
            this.mLogClearsOnClose = pLogClearsOnClose;
            this.mAutoRead = pAutoread;
        }

        [CategoryAttribute("Game Properties"), DescriptionAttribute("Display Name of the Game")]
        public String GameName
        {
            get { return this.mGameName; }
            set { this.mGameName = value; }
        }

        [EditorAttribute(typeof(OpenFiledialogUIEditor), typeof(UITypeEditor)), CategoryAttribute("Log File Properties"), DescriptionAttribute("File Path of the Combat Log")]
        public String LogFilePath
        {
            get { return this.mLogFilePath; }
            set { this.mLogFilePath = value; }
        }

        [CategoryAttribute("Log File Properties"), DescriptionAttribute("Seperation Characters between Entries in the Log")]
        public String EntrySeperator
        {
            get { return this.mEntrySeperator; }
            set { this.mEntrySeperator = value; }
        }

        [CategoryAttribute("Time Stamp Properties"), DescriptionAttribute("Seperation Characters between Entries in the Log")]
        public TimeStampFormat TimeFormat
        {
            get { return this.mTimeStampFormat; }
            set { this.mTimeStampFormat = value; }
        }

        [CategoryAttribute("Time Stamp Properties"), DescriptionAttribute("Format of the DateTimeString i.e. MM/DD/YYYY hh:mm:ss")]
        public String DateTimeStringFormat
        {
            get { return this.mDateTimeStringFormat; }
            set { this.mDateTimeStringFormat = value; }
        }

        [CategoryAttribute("Time Stamp Properties"), DescriptionAttribute("DateTime that an epoch value of 0 represents")]
        public DateTime EpochTime
        {
            get { return this.mEpochTime; }
            set { this.mEpochTime = value; }
        }

        [CategoryAttribute("Time Stamp Properties"), DescriptionAttribute("Is the epoch time known so that we can print specific datetimes, or should all times be relative from the first entry")]
        public bool UseFullTimes
        {
            get { return this.mUseFullTimes; }
            set { this.mUseFullTimes = value; }
        }

        [CategoryAttribute("Log File Properties"), DescriptionAttribute("Is the log empty every time the game starts")]
        public bool LogFileClearOnClose
        {
            get { return this.mLogClearsOnClose; }
            set { this.mLogClearsOnClose = value; }
        }

        [CategoryAttribute("Log File Properties"), DescriptionAttribute("Can the log file be automatically monitored for changes, or must updates be pulled")]
        public bool AutoRead
        {
            get { return this.mAutoRead; }
            set { this.mAutoRead = value; }
        }

        [CategoryAttribute("Log File Properties"), DescriptionAttribute("List of String formats to accept and how to handle them")]
        public List<ParsableLogEntry> LogEntries
        {
            get { return this.Entries; }
            set { this.Entries = value; }
        }

        [CategoryAttribute("Game Properties"), DescriptionAttribute("Name of your character")]
        public String PlayerName
        {
            get { return this.mPlayerName; }
            set { this.mPlayerName = value; }
        }
    }
}
